package com.rachel.materialdemo.activity;

import android.os.Bundle;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;

import com.rachel.materialdemo.R;

public class TestDetailActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_detail);
        int resid = getIntent().getIntExtra("imgid",R.mipmap.ic_launcher);
        String text = getIntent().getStringExtra("string");


        //设置 toolbar
        Toolbar toolbar = (Toolbar) findViewById(R.id.test_toolbar);
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null){
            //默认就是返回图标
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
        // 设置 imageview and textview
        ImageView imageView = (ImageView) findViewById(R.id.test_img);
        TextView textView = (TextView) findViewById(R.id.test_text);

        imageView.setImageResource(resid);
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < 20; i++) {
            sb.append(text+"  ");

        }
        textView.setText(sb.toString());


        // 设置滚动方面的
        CollapsingToolbarLayout collapsingToolbarLayout =
                (CollapsingToolbarLayout)findViewById(R.id.test_coll);

        collapsingToolbarLayout.setTitle(text);
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home){
            finish();
        }
        return true;
    }
}
